package com.zh.hbase;




import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;

public class TestHBaseDriver extends Configured implements Tool {

	public int run(String[] args) throws Exception {
		Configuration conf = this.getConf();
		//设置JOB
		Job job = Job.getInstance(conf,"hbase-mr");
		job.setJarByClass(TestHBaseDriver.class);
		//设置参数
		Scan scan = new Scan();
		TableMapReduceUtil.initTableMapperJob("stu_info", scan, TestHBaseMapper.class,ImmutableBytesWritable.class, Put.class, job);
		//只给reduce初始化，不给实例
		TableMapReduceUtil.initTableReducerJob("mr_tb", null, job);
		job.setNumReduceTasks(1);
		
		return job.waitForCompletion(true)?0:1;
	}
	
	public static void main(String[] args) {
		//读取配置文件
		Configuration conf = HBaseConfiguration.create();
		try {
			int status = ToolRunner.run(conf, new TestHBaseDriver(), args);
			System.exit(status);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
}
